package com.ymatou.iapi.app.keyword.testcase;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.app.keyword.parameter.ProductBySellerBean;
import com.ymatou.iapi.app.keyword.service.ProductBySellerCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.SearchWapper;

public class Ts_ProductBySeller {
	private static ProductBySellerBean productbysellerBean;
	private static ProductBySellerCall productbysellerCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("买手页商品搜索以及类目品牌聚合搜索接口");
	}

	@Before
	public void caseUp() {
		productbysellerBean=new ProductBySellerBean();
		productbysellerCall=new ProductBySellerCall();
		
	}

	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(productbysellerCall.getOpurl());
		
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_001() {
		Logger.start(true,"买手页商品搜索，检查返回数据总数与数据库中统计是否一样 ");
		try {
			//设置参数
			int uid = 2379434;
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("sproductid,source");
			productbysellerBean.setLimit("0,20");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			Logger.verifyEquals("OK", productbysellerCall.getStatus(), "验证接口返回状态是否正常");
			//得到接口返回数据
			String iBrandId=null;
			String iThirdCategoryIds =null;
			List<Map> productList = new SearchWapper().getProductBySellerId(uid,iBrandId,iThirdCategoryIds,"");
			
			Logger.verifyEquals(productbysellerCall.getTotal(), productList.size(), "检查接口返回的total总数与数据库中统计的值是否一致");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_002() {
		Logger.start(true,"买手页商品搜索，检查接口返回数据是否有重复值 ");
		try {
			//设置参数
			int uid = 2379434;
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("sproductid,source");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			Logger.verifyEquals("OK", productbysellerCall.getStatus(), "验证接口返回状态是否正常");
		
			JSONArray hitsAry = productbysellerCall.getHits();
			
			List<String> list = new ArrayList<String>();

			for (int i = 1; i <= hitsAry.length(); i++) {
				
				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);
				
				String id = json.getString("sproductid");
				
				if (list.contains(id) == true) {

					Logger.verifyEquals(false, list.contains(id), "验证第" + i+ "条返回数据的id存在重复值" + id);

				}else{
					Logger.verifyEquals(false, list.contains(id), "验证第" + i+ "条返回数据的id不存在重复值" + id);
					list.add(id);
				}
			
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_003() {
		Logger.start(true,"买手页商品搜索，检查每条返回商品信息字段值是否完整 ");
		try {
			//设置参数
			int uid = 2379434;
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setLimit("0,20");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			Logger.verifyEquals("OK", productbysellerCall.getStatus(), "验证接口返回状态是否正常");
			
			JSONArray hitsAry = productbysellerCall.getHits();
			

			for (int i = 1; i <= hitsAry.length(); i++) {
				
				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);
				
				Logger.verifyNotNull(json.getString("sproductid"), "检查第"+i+"条记录中的sproductid值是否为空");
				Logger.verifyNotNull(json.getString("source"), "检查第"+i+"条记录中的source值是否为空");
				Logger.verifyNotNull(json.getString("ithirdcategoryid"), "检查第"+i+"条记录中的ithirdcategoryid值是否为空");
				Logger.verifyNotNull(json.getString("ibrandid"), "检查第"+i+"条记录中的ibrandid值是否为空");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_004() {
		Logger.start(true,"买手页商品搜索，检查返回的公共数据 ");
		try {
			//设置参数
			int uid = 2379434;
			String requestid = "111222";
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("sproductid,source");
			productbysellerBean.setLimit("0,20");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid(requestid);
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			Logger.verifyEquals("OK", productbysellerCall.getStatus(), "验证接口返回状态是否正常");
			Logger.verifyEquals("OK",productbysellerCall.getCommonInfo("status") , "检查接口状态值");
			Logger.verifyNotNull(productbysellerCall.getCommonInfo("took"), "took不为空");
			Logger.verifyEquals(false, productbysellerCall.getCommonInfoBoo("downgrade"), "验证downgrade返回false");
			Logger.verifyEquals(requestid,productbysellerCall.getCommonInfo("requestid") , "检查接口请求id值");
			Logger.verifyEquals(false, productbysellerCall.getCommonInfoBoo("timeout"), "验证timeout返回flase");
			Logger.verifyNotNull(productbysellerCall.getCommonInfo("hostip"), "验证hostip不为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_005() {
		Logger.start(true,"买手页商品搜索，检查接口返回stats集合里的类目和品牌 ");
		try {
			//设置参数
			int uid = 2379434;
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("sproductid,source");
			productbysellerBean.setLimit("0,20");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			 JSONObject statsObject =  (JSONObject) productbysellerCall.getStats();
			
			 Logger.verifyEquals(true, statsObject.has("ithirdcategoryid"), "stats中是否有返回类目统计");
			 Logger.verifyEquals(true, statsObject.has("ibrandid"), "stats中是否包含返回品牌统计");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_006() {
		Logger.start(true,"买手页商品搜索，检查接口返回商品类型是否为M端商品 ");
		try {
			//设置参数
			int uid = 2379434;
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("sproductid,source");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			JSONArray hitsAry = productbysellerCall.getHits();
			
			for (int i = 1; i <= hitsAry.length(); i++) {
				
				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);
				String sproductid = json.getString("sproductid");
				
				//检查M端库中是否包含该商品
				List<Map> productInfo = new SearchWapper().selectProductInfo(sproductid);
				
				Logger.verifyNotNull(productInfo.size(), "验证商品id为:"+sproductid+"的商品记录是否为M端商品");
				
			} 
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_007() {
		Logger.start(true,"买手页商品搜索，检查接口返回商品对应的买手是否在白名单");
		try {
			//设置参数
			int uid = 2379434;
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			JSONArray hitsAry = productbysellerCall.getHits();
			
			for (int i = 1; i <= hitsAry.length(); i++) {
				
				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);
				String sproductid = json.getString("sproductid");
				int iuserid = json.getInt("iuserid");
				
				//查库检查用户是否在白名单中
				boolean SellerAttributeInfo = new SearchWapper().getSellerAttributeInfo(iuserid);
				
				Logger.verifyEquals(true, SellerAttributeInfo, "验证商品id为:"+sproductid+"的商品所对应的用户id为："+iuserid+"的用户是否在白名单中");
				
			} 
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_008() {
		Logger.start(true,"买手页商品搜索，检查接口返回商品对应的物流方式是否是贝海直邮，贝海保税，卖家保税其中一种");
		try {
			//设置参数
			int uid = 2379434;
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			JSONArray hitsAry = productbysellerCall.getHits();
			
			for (int i = 1; i <= hitsAry.length(); i++) {
				
				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);
				String sproductid = json.getString("sproductid");
				int iuserid = json.getInt("iuserid");
				
				//查库检查商品对应的物流方式
				List<Map> ProductLists = null;
				ProductLists = new SearchWapper().selectProductInfo(sproductid);
				
				if((Integer) ProductLists.get(0).get("isailprotected")==1 || (Integer) ProductLists.get(0).get("iCatalogStatus")==4 || (Integer) ProductLists.get(0).get("iCatalogStatus")==5 ){
					Logger.verifyEquals(true, true, "检查第"+i+i+"条商品id为:"+sproductid+"条商品的物流方式是贝海直邮，贝海保税，卖家保税之一");
				}else{
					Logger.verifyEquals(true, false, "检查第"+i+"条商品id为:"+sproductid+"的物流方式是贝海直邮，贝海保税，卖家保税之一");
				}
				
			} 
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_009() {
		Logger.start(true,"买手页商品搜索，检查接口返回商品是否在有效期内，状态是否为上架状态");
		try {
			//设置参数
			int uid = 2379434;
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			JSONArray hitsAry = productbysellerCall.getHits();
			
			for (int i = 1; i <= hitsAry.length(); i++) {
				
				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);
				String sproductid = json.getString("sproductid");
				int iuserid = json.getInt("iuserid");
				
				//查库检查商品状态及库存
				List<Map> ProductLists = null;
				ProductLists = new SearchWapper().selectProductInfo(sproductid);
				if(ProductLists.size()<0){
					Logger.verifyEquals(ProductLists.size()>0, ProductLists.size()<0, "检查第"+i+"条商品id为："+sproductid+"的商品在数据库中没有找到");
				}else{
					
					int action = (Integer) ProductLists.get(0).get("iaction");
					Date validend =  (Date) ProductLists.get(0).get("validend");
					long nowTime = new Date().getTime();
					long endTime = validend.getTime();
					Logger.verifyEquals(true, action>-1, "检查第"+i+"条商品id为："+sproductid+"的商品在数据库中状态为有效");
					Logger.verifyEquals(true,endTime>nowTime , "检查第"+i+"条商品id为："+sproductid+"的商品在数据库中还未过期");
				}
				
				
			} 
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_010() {
		Logger.start(true,"买手页商品搜索，检查接口返回商品在数据库中库存 数要大于0");
		try {
			//设置参数
			int uid = 2379434;
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			JSONArray hitsAry = productbysellerCall.getHits();
			
			for (int i = 1; i <= hitsAry.length(); i++) {
				
				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);
				String sproductid = json.getString("sproductid");
				int iuserid = json.getInt("iuserid");
				
				//查库检查商品库存
				List<Map> ProductLists = null;
				ProductLists = new SearchWapper().selectProductInfo(sproductid);
				if(ProductLists.size()<0){
					Logger.verifyEquals(ProductLists.size()>0, ProductLists.size()<0, "检查第"+i+"条商品id为："+sproductid+"的商品在数据库中没有找到");
				}else{
					
					int stockNum = (Integer) ProductLists.get(0).get("itotalstock");
					
					Logger.verifyEquals(true, stockNum>0, "检查第"+i+"条商品id为："+sproductid+"的商品在数据库中库存数大于0");
					
				}
				
			} 
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_011() {
		Logger.start(true,"买手页商品搜索，检查接口返回商品对比数据库是否属于砍价团商品");
		try {
			//设置参数
			int uid = 2379434;
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			JSONArray hitsAry = productbysellerCall.getHits();
			
			for (int i = 1; i <= hitsAry.length(); i++) {
				
				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);
				String sproductid = json.getString("sproductid");
				int iuserid = json.getInt("iuserid");
				
				//查库检查商品库存
				List<Map> HiddenProductLists = null;
				HiddenProductLists = new SearchWapper().getHiddenProductInfo(sproductid);
				Logger.verifyEquals(null, HiddenProductLists.size()==0 ? null:HiddenProductLists.size(), "验证第"+i+"条商品id为:"+sproductid+"的记录不存在隐藏商品表中");
				
			} 
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_012() {
		Logger.start(true,"买手页商品搜索，检查分页功能是否正常  ");
		try {
			//设置参数
			int uid = 2379434;
			int onePage = 2; //设置每页显示2条数据
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setLimit("0,"+onePage+"");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			Logger.verifyEquals(onePage, productbysellerCall.getHits().length(), "查看每页是否显示"+onePage+"条记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_013() {
		Logger.start(true,"买手页商品搜索，检查返回stats中统计的类目值下对应的商品数与数据库中统计的是否一致  ");
		try {
			//设置参数
			int uid = 2379434;
			int onePage = 10; //设置每页显示2条数据
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setLimit("0,"+onePage+"");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();	
			
			JSONObject statsObject =  (JSONObject) productbysellerCall.getStats();
			String iThirdCategoryIdString = statsObject.getString("ithirdcategoryid");
			JSONObject iThirdCategoryIdObject = new JSONObject(iThirdCategoryIdString);
			
			//获取json里的所有键名存入数组
			 String[] iThirdCategoryIdKey = productbysellerCall.analyzeJsonToArray(iThirdCategoryIdObject, "key");
			 
			//获取json里所有值存入数组
			 String[] iThirdCategoryIdValue = productbysellerCall.analyzeJsonToArray(iThirdCategoryIdObject, "value");
			 
			 String iBrandId = null;
			 
			for(int i=1;i<=iThirdCategoryIdKey.length;i++){
				
				String iThirdCategoryId= iThirdCategoryIdKey[i-1];
				String iThirdCategoryIdForProduct = iThirdCategoryIdValue[i-1];
				
				//获取数据库中对应类目的商品记录
				List<Map> productList = new SearchWapper().getProductBySellerId(uid,iBrandId,iThirdCategoryId,"");
				
				Logger.verifyEquals(productList.size(),Integer.parseInt(iThirdCategoryIdForProduct), "检查用户id为："+uid+",类目为:"+iThirdCategoryId+"的商品总数是否与数据路统计一致");
			}
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_014() {
		Logger.start(true,"买手页商品搜索，检查返回stats中统计的品牌值下对应的商品数与数据库中统计的是否一致  ");
		try {
			//设置参数
			int uid = 2379434;
			int onePage = 10; //设置每页显示2条数据
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setLimit("0,"+onePage+"");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();	
			
			JSONObject statsObject =  (JSONObject) productbysellerCall.getStats();
			String ibrandidString = statsObject.getString("ibrandid");
			JSONObject ibrandidObject = new JSONObject(ibrandidString);
			
			//获取json里的所有键名存入数组
			 String[] ibrandidKey = productbysellerCall.analyzeJsonToArray(ibrandidObject, "key");
			 
			//获取json里所有值存入数组
			 String[] ibrandidValue = productbysellerCall.analyzeJsonToArray(ibrandidObject, "value");
			 
			 String iThirdCategoryId = null;
			 
			for(int i=1;i<=ibrandidKey.length;i++){
				
				String ibrandidId= ibrandidKey[i-1];
				String ibrandidForProduct = ibrandidValue[i-1];
				
				//获取数据库中对应类目的商品记录
				List<Map> productList = new SearchWapper().getProductBySellerId(uid,ibrandidId,iThirdCategoryId,"");
				
				Logger.verifyEquals(productList.size(),Integer.parseInt(ibrandidForProduct), "检查用户id为："+uid+",品牌为:"+ibrandidId+"的商品总数是否与数据路统计一致");
			}
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_015() {
		Logger.start(true,"买手页类目聚合页搜索，返回数据总记录数与数据库统计是否一致 ");
		try {
			//设置参数
			int uid = 2379434;
			String ithirdcategoryid = "1097";
			int onePage = 10; //设置每页显示2条数据
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("and(term(iuserid,"+uid+"),term(ithirdcategoryid,"+ithirdcategoryid+"))");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setLimit("0,"+onePage+"");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();	
			
			//查库统计对应用户对应类目下的商品信息
			String iBrandId = null;
			List<Map> productList = new SearchWapper().getProductBySellerId(uid,iBrandId,ithirdcategoryid,"");
			
			Logger.verifyEquals(productList.size(), productbysellerCall.getTotal(), "检查返回数据总记录数与数据库统计的是否一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_016() {
		Logger.start(true,"买手页类目聚合页搜索，检查接口返回商品是否满足卖家主页商品搜索过滤要求及类目过滤条件 ");
		try {
			//设置参数
			int uid = 2379434;
			String ithirdcategoryid = "1097";
			int onePage = 10; //设置每页显示2条数据
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("and(term(iuserid,"+uid+"),term(ithirdcategoryid,"+ithirdcategoryid+"))");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setLimit("0,"+onePage+"");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();	
			
			//查库统计对应用户对应类目下的商品信息
			String iBrandId = null;
			List<Map> productList = new SearchWapper().getProductBySellerId(uid,iBrandId,ithirdcategoryid,"");
			
			Map map=new HashMap();
			
			for(int i=1;i<=productList.size();i++){
				String sproductid = (String) productList.get(i-1).get("sproductid");
				map.put("sproductid"+i, sproductid);
				
			}
			
			for(int i=1;i<= productbysellerCall.getHits().length();i++){
				
				String info = productbysellerCall.getHits().get(i - 1).toString();
				JSONObject infoAry = new JSONObject(info);
				
				String productId = (String) infoAry.get("sproductid");
				
				Logger.verifyEquals(true, map.containsValue(productId), "检查第"+i+"条数据，商品id为:"+productId+"的数据是否包含在所有满足卖家主页商品搜索的数据中");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_017() {
		Logger.start(true,"买手页品牌聚合页搜索，返回数据总记录数与数据库统计是否一致 ");
		try {
			//设置参数
			int uid = 2379434;
			String ibrandid = "14494";
			int onePage = 10; //设置每页显示2条数据
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("and(term(iuserid,"+uid+"),term(ibrandid,"+ibrandid+"))");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setLimit("0,"+onePage+"");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();	
			
			//查库统计对应用户对应品牌下的商品信息
			String ithirdcategoryid = null;
			List<Map> productList = new SearchWapper().getProductBySellerId(uid,ibrandid,ithirdcategoryid,"");
			
			Logger.verifyEquals(productList.size(), productbysellerCall.getTotal(), "检查返回数据总记录数与数据库统计的是否一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_018() {
		Logger.start(true,"买手页品牌聚合页搜索，检查接口返回商品是否满足卖家主页商品搜索过滤要求及品牌过滤条件 ");
		try {
			//设置参数
			int uid = 2379434;
			String ibrandid = "14494";
			int onePage = 10; //设置每页显示2条数据
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("and(term(iuserid,"+uid+"),term(ibrandid,"+ibrandid+"))");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setLimit("0,"+onePage+"");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();	
			
			//查库统计对应用户对应品牌下的商品信息
			String ithirdcategoryid = null;
			List<Map> productList = new SearchWapper().getProductBySellerId(uid,ibrandid,ithirdcategoryid,"");
			
			Map map=new HashMap();
			
			for(int i=1;i<=productList.size();i++){
				String sproductid = (String) productList.get(i-1).get("sproductid");
				map.put("sproductid"+i, sproductid);
				
			}
			
			Logger.debug(FormatUtil.beanToGSONString(map));
			for(int i=1;i<= productbysellerCall.getHits().length();i++){
				
				String info = productbysellerCall.getHits().get(i - 1).toString();
				JSONObject infoAry = new JSONObject(info);
				
				String productId = (String) infoAry.get("sproductid");
				
				Logger.verifyEquals(true, map.containsValue(productId), "检查第"+i+"条数据，商品id为:"+productId+"的数据是否包含在所有满足卖家主页商品搜索的数据中");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_019() {
		Logger.start(false,"买手页商品搜索，传入一个不存在的买手id，检查接口返回结果及数据");
		try {
			//设置参数
			int uid = 1111111;
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("sproductid,source");
			productbysellerBean.setLimit("0,20");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			JSONObject statsObject =  (JSONObject) productbysellerCall.getStats();
			String ibrandidString = statsObject.getString("ibrandid") ;
			String ithirdcategoryidString = statsObject.getString("ithirdcategoryid");
			
			Logger.verifyEquals("OK", productbysellerCall.getStatus(), "验证接口返回状态是否正常");
			Logger.verifyEquals(true, productbysellerCall.getHits().length()<=2, "接口没有返回数据");
			Logger.verifyEquals(true, ibrandidString.length()<=2, "没有对应的品牌数据返回");
			Logger.verifyEquals(true, ithirdcategoryidString.length()<=2, "没有对应的类目数据返回");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_020() {
		Logger.start(false,"买手页商品搜索，传入一个被惩罚的买手id，检查接口返回结果及数据");
		try {
			//设置参数
			int uid = 305966;
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("term(iuserid,"+uid+")");
			productbysellerBean.setFl("sproductid,source");
			productbysellerBean.setLimit("0,20");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			productbysellerBean.setStat("term(ibrandid),term(ithirdcategoryid)");
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();			
			
			JSONObject statsObject =  (JSONObject) productbysellerCall.getStats();
			String ibrandidString = statsObject.getString("ibrandid") ;
			String ithirdcategoryidString = statsObject.getString("ithirdcategoryid");
			
			Logger.verifyEquals("OK", productbysellerCall.getStatus(), "验证接口返回状态是否正常");
			Logger.verifyEquals(true, productbysellerCall.getHits().length()<=2, "接口没有返回数据");
			Logger.verifyEquals(true, ibrandidString.length()<=2, "没有对应的品牌数据返回");
			Logger.verifyEquals(true, ithirdcategoryidString.length()<=2, "没有对应的类目数据返回");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_021() {
		Logger.start(false,"买手页类目聚合页搜索，传入一个买手商品中不存在的类目id，检查接口返回结果及数据 ");
		try {
			//设置参数
			int uid = 2379434;
			String ithirdcategoryid = "11111";
			int onePage = 10; //设置每页显示2条数据
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("and(term(iuserid,"+uid+"),term(ithirdcategoryid,"+ithirdcategoryid+"))");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setLimit("0,"+onePage+"");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();	
			
			Logger.verifyEquals("OK", productbysellerCall.getStatus(), "验证接口返回状态是否正常");
			Logger.verifyEquals(true, productbysellerCall.getHits().length()<=2, "接口没有返回数据");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductBySeller_022() {
		Logger.start(false,"买手页品牌聚合页搜索，传入一个买手商品中不存在的品牌id，检查接口返回结果及数据 ");
		try {
			//设置参数
			int uid = 2379434;
			String ibrandid = "1111";
			int onePage = 10; //设置每页显示2条数据
			productbysellerBean.setModule("productbyseller");
			productbysellerBean.setExplain("False");
			productbysellerBean.setFilter("and(term(iuserid,"+uid+"),term(ibrandid,"+ibrandid+"))");
			productbysellerBean.setFl("iuserid,sproductid,source,ithirdcategoryid,ibrandid");
			productbysellerBean.setLimit("0,"+onePage+"");
			productbysellerBean.setAppkey(1);
			productbysellerBean.setPlatform("pc");
			
			productbysellerBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue");
			productbysellerBean.setRequestid("111222");
			
			productbysellerCall.setData(productbysellerBean);
			productbysellerCall.callService();	
			
			Logger.verifyEquals("OK", productbysellerCall.getStatus(), "验证接口返回状态是否正常");
			Logger.verifyEquals(true, productbysellerCall.getHits().length()<=2, "接口没有返回数据");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	//TODO  isTop=1的商品排在前面
}
